<template>
  <div class="carousel-wrapper">
    <v-carousel
      v-model="currentSlide"
      hide-delimiters
      :show-arrows="false"
      cycle
      height="auto"
    >
      <v-carousel-item v-for="(slide, i) in slides" :key="i">
        <div class="carousel-content">
          <img :src="slide.image" alt="Treasure Chest" />
        </div>
      </v-carousel-item>
    </v-carousel>

    <!-- 自定义焦点指示器 -->
    <div class="custom-indicators">
      <span
        v-for="(slide, index) in slides"
        :key="index"
        :class="{ active: currentSlide === index }"
        @click="changeSlide(index)"
      ></span>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from "vue";
import request from "@/static/img/set/request.png";

export default defineComponent({
  name: "FocusCarousel",
  setup() {
    const slides = [
      { image: request },
      { image: request },
      { image: request },
      // 可以添加更多幻灯片
    ];

    const currentSlide = ref(0);  // 使用 v-model 绑定当前显示的幻灯片索引

    const changeSlide = (index: number) => {
      currentSlide.value = index;
    };

    return {
      slides,
      currentSlide,  // 返回 currentSlide 用于模板中的 v-model
      changeSlide,
      handleViewClick: () => {
        // 处理查看按钮点击事件
        console.log("查看按钮被点击");
      },
    };
  },
});
</script>

<style scoped lang="scss">
.carousel-wrapper {
  position: relative; // 必须，作为定位上下文
  width: 100%;
  height: 100%; // 确保容器有明确的高度

  .carousel-content {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0; // 移除 padding 以便图片可以占满整个容器
    // background-color: #333;

    img {
      width: 100%; // 设置宽度为100%
      height: 100%; // 设置高度为100%
      object-fit: cover; // 保持图片比例并裁剪多余部分
    }
  }

  .custom-indicators {
    position: absolute;
    bottom: 30px;     // 距离底部
    left: 30px;       // 距离左边
    display: flex;
    z-index: 10;      // 确保在图片之上

    span {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background-color: #ccc;
      margin: 0 4px;
      cursor: pointer;
      transition: background-color 0.3s ease;

      &.active {
        background-color: orange;
      }
    }
  }
}
</style>